<%@ page import="util.JDBC" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="util.JSON" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    response.setCharacterEncoding("utf-8");
    response.setContentType("text/html;charset=utf-8");

    String username=request.getParameter("username");
    String password=request.getParameter("password");
    System.out.println("username:"+username+"  password:"+password);

    //判断账号是否已存在
    String sql="select count(*) as count from user where username='"+username+"'";
    //执行sql语句
    System.out.println(sql);
    JDBC.connectionTest();
    ResultSet rs=JDBC.executeQuery(sql);
    int count=0;
    while (rs.next()){
        count=rs.getInt("count");
    }
    if(count!=0){
        JSON json=new JSON("status","error");
        json.put("message","注册失败，账户已存在！");
        out.print(json.getJson());
    }else{
        sql="insert into user(username,password) values('"+username+"','"+password+"')";
        JDBC.connectionTest();
        JDBC.executeUpdate(sql);
        JSON json=new JSON("status","success");
        json.put("message","注册成功！");
        out.print(json.getJson());
    }
%>